package com.pai4j.message.builder.interaction;

import com.pai4j.common.constants.MessageConstants;
import com.pai4j.common.enums.InteractionMessageTypeEnum;
import com.pai4j.domain.vo.dto.LikeCollectMessageDTO;
import com.pai4j.domain.vo.dto.ResourceMessageDTO;
import com.pai4j.message.core.builder.AbstractMessageBuilder;
import lombok.extern.slf4j.Slf4j;

/**
 * 点赞消息构建器
 * 用于构建点赞互动消息
 *
 * @author PAI4J Team
 * @date 2025-11-01
 */
@Slf4j
public class LikeMessageBuilder extends AbstractMessageBuilder<LikeCollectMessageDTO> {

    public LikeMessageBuilder() {
        super();
        // 设置默认消息类型
        context.setMessageTypeEnum(InteractionMessageTypeEnum.LIKE);
        context.setType(MessageConstants.TypeEnum.LIKE.getType());
        context.setCategory(MessageConstants.CategoryEnum.LIKE_COLLECT.getCategory());
    }

    @Override
    protected String getMessageCategory() {
        return MessageConstants.CategoryEnum.LIKE_COLLECT.getCategory();
    }

    @Override
    protected LikeCollectMessageDTO createMessageDTO() {
        return new LikeCollectMessageDTO();
    }

    @Override
    protected void fillMessageDTO(LikeCollectMessageDTO messageDTO) {
        // 填充资源信息
        if (context.getResourceType() != null) {
            messageDTO.setResourceType(context.getResourceType());
        }
        if (context.getResourceId() != null) {
            messageDTO.setResourceId(context.getResourceId());
        }

        // 如果内容为空，使用默认模板
        if (messageDTO.getContent() == null && context.getResourceInfo() != null) {
            String defaultContent = String.format("点赞了你的%s", 
                    context.getResourceInfo().getDisplayTitle());
            messageDTO.setContent(defaultContent);
        }
    }

    @Override
    protected String[] getTemplateVarNames() {
        return new String[]{"userName", "resourceType", "resourceTitle"};
    }

    /**
     * 快速构建点赞消息
     */
    public static LikeMessageBuilder create() {
        return new LikeMessageBuilder();
    }
}

